package 力扣日常刷题.木22二月.第11天217;

import 力扣日常刷题.ListNode;

import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/2/17
 * @description
 */
public class Demo84反转链表 {

    // 递归
    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode nHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return nHead;
    }


    public ListNode reverseList2(ListNode head) {
        ListNode pre = null,cur = head;
        while(cur != null){
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }

}
